home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / next.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  13.5 KB  |  483 lines

  1. /*
  2.  * $Id: next.trm,v 1.10 1995/12/20 21:48:02 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - next.trm */
  7. /*
  8.  * Copyright (C) 1991, 1992   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *     next
  26.  *
  27.  * AUTHORS
  28.  *  Nick Strobel from Russell Lang's post.trm
  29.  * 
  30.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  31.  *
  32.  * The 'postscript' driver produces landscape output 10" wide and 7" high.  
  33.  * To get a smaller epsf output use 'set size 0.5,0.5', 
  34.  * 'set term postscript portrait', make only one plot per file
  35.  * and change the first line of the postscript file from
  36.  * '%!PS-Adobe-2.0' to '%!PS-Adobe-2.0 EPSF-2.0'
  37.  * To change font to Times-Roman and font size to 20pts use 
  38.  * 'set term postscript "Times-Roman" 20'.
  39.  */
  40. #ifndef GOT_DRIVER_H
  41. #include "driver.h"
  42. #endif
  43.  
  44. #ifdef TERM_REGISTER
  45. register_term(next)
  46. #endif
  47.  
  48. #ifdef TERM_PROTO
  49. #include <stdlib.h>
  50. #include "epsviewe.h"
  51. TERM_PUBLIC void NEXT_options __P((void));
  52. TERM_PUBLIC void NEXT_init __P((void));
  53. TERM_PUBLIC void NEXT_graphics __P((void));
  54. TERM_PUBLIC void NEXT_text __P((void));
  55. TERM_PUBLIC void NEXT_reset __P((void));
  56. TERM_PUBLIC void NEXT_linetype __P((int linetype));
  57. TERM_PUBLIC void NEXT_move __P((unsigned int x, unsigned int y));
  58. TERM_PUBLIC void NEXT_vector __P((unsigned int x, unsigned int y));
  59. TERM_PUBLIC void NEXT_put_text __P((unsigned int x, unsigned int y, char *str));
  60. TERM_PUBLIC int NEXT_text_angle __P((int ang));
  61. TERM_PUBLIC int NEXT_justify_text __P((enum JUSTIFY mode));
  62. TERM_PUBLIC void NEXT_point __P((unsigned int x, unsigned int y, int number));
  63.  
  64. #define NEXT_XOFF    50    /* page offset in pts */
  65. #define NEXT_YOFF    50
  66.  
  67. #define NEXT_XMAX 7200
  68. #define NEXT_YMAX 5040
  69.  
  70. #define NEXT_XLAST (NEXT_XMAX - 1)
  71. #define NEXT_YLAST (NEXT_YMAX - 1)
  72.  
  73. #define NEXT_VTIC (NEXT_YMAX/80)
  74. #define NEXT_HTIC (NEXT_YMAX/80)
  75.  
  76. #define NEXT_SC (10)                /* scale is 1pt = 10 units */
  77. #define    NEXT_LW (0.5*NEXT_SC)        /* linewidth = 0.5 pts */
  78.  
  79. #define NEXT_VCHAR (14*NEXT_SC)        /* default is 14 point characters */
  80. #define NEXT_HCHAR (14*NEXT_SC*6/10)
  81.  
  82. #define GOT_NEXT_PROTO
  83. #endif
  84.  
  85. #ifndef TERM_PROTO_ONLY
  86. #ifdef TERM_BODY
  87.  
  88. /* NeXT driver by Nick Strobel, strobel@phast.phys.washington.edu */
  89. #import <math.h>
  90. #import <dpsclient/dpsclient.h>
  91. #import <dpsclient/dpsNeXT.h>
  92. #import <stdlib.h>
  93. #import "../epsviewe.h"
  94.  
  95. static void window_create __P((float width, float height));
  96.  
  97. static DPSContext d;
  98. static float width,height;    
  99. static float xsize_orig,ysize_orig;  
  100.  
  101. static char next_font[MAX_ID_LEN+1] = "Helvetica" ; /* name of font */
  102. static int next_fontsize = 14;                     /* size of font in pts */
  103. static TBOOLEAN next_portrait = FALSE;                 /* vertical page */
  104. static TBOOLEAN next_color = FALSE;
  105. static TBOOLEAN init_called = FALSE;
  106. static TBOOLEAN initframe_called = FALSE;
  107.  
  108. static int next_page=0;            /* page count */
  109. static int next_path_count=0;     /* count of lines in path */
  110. static int next_ang=0;            /* text angle */
  111. static enum JUSTIFY next_justify=LEFT;    /* text is flush left */
  112.  
  113. static char *NEXT_header[] = {
  114. "/vpt2 vpt 2 mul def\n",
  115. "/hpt2 hpt 2 mul def\n",
  116. /* flush left show */
  117. "/Lshow { currentpoint stroke moveto\n",
  118. "  0 vshift rmoveto show } def\n", 
  119. /* flush right show */
  120. "/Rshow { currentpoint stroke moveto\n",
  121. "  dup stringwidth pop neg vshift rmoveto show } def\n", 
  122. /* centred show */
  123. "/Cshow { currentpoint stroke moveto\n",
  124. "  dup stringwidth pop -2 div vshift rmoveto show } def\n", 
  125. /* Dash or Color Line */
  126. "/DL { Color {setrgbcolor [] 0 setdash pop}\n",
  127. " {pop pop pop 0 setdash} ifelse } def\n",
  128. /* Border Lines */
  129. "/BL { stroke gnulinewidth 2 mul setlinewidth } def\n",
  130. /* Axes Lines */
  131. "/AL { stroke gnulinewidth 2 div setlinewidth } def\n",
  132. /* Plot Lines */
  133. "/PL { stroke gnulinewidth setlinewidth } def\n",
  134. /* Line Types */
  135. "/LTb { BL [] 0 0 0 DL } def\n", /* border */
  136. "/LTa { AL [1 dl 2 dl] 0 setdash 0 0 0 setrgbcolor } def\n", /* axes */
  137. "/LT0 { PL [] 0 1 0 DL } def\n",
  138. "/LT1 { PL [4 dl 2 dl] 0 0 1 DL } def\n",
  139. "/LT2 { PL [2 dl 3 dl] 1 0 0 DL } def\n",
  140. "/LT3 { PL [1 dl 1.5 dl] 1 0 1 DL } def\n",
  141. "/LT4 { PL [5 dl 2 dl 1 dl 2 dl] 0 1 1 DL } def\n",
  142. "/LT5 { PL [4 dl 3 dl 1 dl 3 dl] 1 1 0 DL } def\n",
  143. "/LT6 { PL [2 dl 2 dl 2 dl 4 dl] 0 0 0 DL } def\n",
  144. "/LT7 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 1 0.3 0 DL } def\n",
  145. "/LT8 { PL [2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 2 dl 4 dl] 0.5 0.5 0.5 DL } def\n",
  146. "/M {moveto} def\n",
  147. "/L {lineto} def\n",
  148. "/P { stroke [] 0 setdash\n", /* Point */
  149. "  currentlinewidth 2 div sub moveto\n",
  150. "  0 currentlinewidth rlineto  stroke } def\n",
  151. "/D { stroke [] 0 setdash  2 copy  vpt add moveto\n", /* Diamond */
  152. "  hpt neg vpt neg rlineto  hpt vpt neg rlineto\n",
  153. "  hpt vpt rlineto  hpt neg vpt rlineto  closepath  stroke\n",
  154. "  P  } def\n",
  155. "/A { stroke [] 0 setdash  vpt sub moveto  0 vpt2 rlineto\n", /* Plus (Add) */
  156. "  currentpoint stroke moveto\n",
  157. "  hpt neg vpt neg rmoveto  hpt2 0 rlineto stroke\n",
  158. "  } def\n",
  159. "/B { stroke [] 0 setdash  2 copy  exch hpt sub exch vpt add moveto\n", /* Box */
  160. "  0 vpt2 neg rlineto  hpt2 0 rlineto  0 vpt2 rlineto\n",
  161. "  hpt2 neg 0 rlineto  closepath  stroke\n",
  162. "  P  } def\n",
  163. "/C { stroke [] 0 setdash  exch hpt sub exch vpt add moveto\n", /* Cross */
  164. "  hpt2 vpt2 neg rlineto  currentpoint  stroke  moveto\n",
  165. "  hpt2 neg 0 rmoveto  hpt2 vpt2 rlineto stroke  } def\n",
  166. "/T { stroke [] 0 setdash  2 copy  vpt 1.12 mul add moveto\n", /* Triangle */
  167. "  hpt neg vpt -1.62 mul rlineto\n",
  168. "  hpt 2 mul 0 rlineto\n",
  169. "  hpt neg vpt 1.62 mul rlineto  closepath  stroke\n",
  170. "  P  } def\n",
  171. "/S { 2 copy A C} def\n", /* Star */
  172. NULL
  173. };
  174.  
  175.  
  176. static double NEXT_init_pointsize;  /* pointsize at term init */
  177.  
  178. TERM_PUBLIC void NEXT_options()
  179. {
  180.     if (!END_OF_COMMAND) {
  181.         if (almost_equals(c_token,"p$ortrait")) {
  182.             next_portrait=TRUE;
  183.             c_token++;
  184.         }
  185.         else if (almost_equals(c_token,"l$andscape")) {
  186.             next_portrait=FALSE;
  187.             c_token++;
  188.         }
  189.         else if (almost_equals(c_token,"d$efault")) {
  190.             next_portrait=FALSE;
  191.             next_color=FALSE;
  192.             strcpy(next_font,"Helvetica");
  193.             next_fontsize = 14;
  194.             c_token++;
  195.         }
  196.     }
  197.  
  198.     if (!END_OF_COMMAND) {
  199.         if (almost_equals(c_token,"m$onochrome")) {
  200.             next_color=FALSE;
  201.             c_token++;
  202.         }
  203.         else if (almost_equals(c_token,"c$olor")) {
  204.             next_color=TRUE;
  205.             c_token++;
  206.         }
  207.     }
  208.  
  209.     if (!END_OF_COMMAND && isstring(c_token)) {
  210.         quote_str(next_font,c_token, MAX_ID_LEN);
  211.         c_token++;
  212.     }
  213.  
  214.     if (!END_OF_COMMAND) {
  215.         /* We have font size specified */
  216.         struct value a;
  217.         next_fontsize = (int)real(const_express(&a));
  218.         c_token++;
  219.         term->v_char = (unsigned int)(next_fontsize*NEXT_SC);
  220.         term->h_char = (unsigned int)(next_fontsize*NEXT_SC*6/10);
  221.     }
  222.  
  223.     sprintf(term_options,"%s %s \"%s\" %d",
  224.         next_portrait ? "portrait" : "landscape",
  225.         next_color ? "color" : "monochrome",next_font,next_fontsize);
  226. }
  227.  
  228.  
  229. TERM_PUBLIC void NEXT_init()
  230. {
  231. struct termentry *t = term;
  232. int i;
  233. float llx,lly,urx,ury;
  234. /* I commented out the postscript comment fields because they are not really 
  235. *  needed (even the bounding box). However, if you'd like to send all the
  236. *  postscript to the context d, they're still there for you
  237. */
  238.  
  239.         llx=NEXT_XOFF;
  240.         lly=NEXT_YOFF;
  241.  
  242.     if(!initframe_called) {
  243.         if(!next_portrait){
  244.             urx=(xsize*(NEXT_XMAX)/NEXT_SC+0.5+NEXT_XOFF);
  245.             ury=(ysize*(NEXT_YMAX)/NEXT_SC+0.5+NEXT_YOFF);
  246.         } else {
  247.             urx=(ysize*(NEXT_YMAX)/NEXT_SC+0.5+NEXT_XOFF);
  248.             ury=(xsize*(NEXT_XMAX)/NEXT_SC+0.5+NEXT_YOFF);
  249.         }
  250.           width=urx-llx;    
  251.           height=ury-lly;
  252.           xsize_orig=xsize;
  253.           ysize_orig=ysize;    
  254.           (void)window_create(width,height);
  255.              d=DPSGetCurrentContext();
  256.        DPSPrintf(d,"/showpage {initgraphics} bind def\n");
  257.       }
  258.         DPSPrintf(d,"1 setgray\n");
  259.         DPSPrintf(d,"0 1 %g %g rectfill\n",rint(width),rint(height));
  260.         DPSPrintf(d,"0 setgray\n");
  261.         DPSPrintf(d,"0 1 %g %g rectstroke\n",rint(width),rint(height));
  262. //           DPSPrintf(d,"/_the_saved_vm_ save def\n");
  263.         DPSPrintf(d,"%g %g translate\n",-llx,-lly); /* KEEP this IN! */
  264.  
  265. //        DPSPrintf(d,"%%!PS-ADOBE-2.0 EPSF-2.0\n");
  266. //        DPSPrintf(d,"%%%%Creator: gnuplot\n");
  267. //        DPSPrintf(d,"%%%%DocumentFonts: %s\n", next_font);
  268. //        DPSPrintf(d,"%%%%BoundingBox: %d %d ", NEXT_XOFF,NEXT_YOFF);
  269. //        if (!next_portrait)
  270. //            DPSPrintf(d,"%d %d\n",(int)width, (int)height);
  271. //        else 
  272. //            DPSPrintf(d,"%d %d\n",(int)width, (int)height);
  273. //        DPSPrintf(d,"%%%%Pages: (atend)\n");
  274. //        DPSPrintf(d,"%%%%EndComments\n");
  275.         DPSPrintf(d,"/gnudict 40 dict def\ngnudict begin\n");
  276.         DPSPrintf(d,"/Color %s def\n",next_color ? "true" : "false");
  277.         DPSPrintf(d,"/gnulinewidth %.3f def\n",NEXT_LW);
  278.         DPSPrintf(d,"/vshift %d def\n", (int)(t->v_char)/(-3));
  279.         DPSPrintf(d,"/dl {%d mul} def\n",NEXT_SC); /* dash length */
  280.         DPSPrintf(d,"/hpt %.1f def\n", pointsize*NEXT_HTIC/2.0);
  281.         DPSPrintf(d,"/vpt %.1f def\n", pointsize*NEXT_VTIC/2.0);
  282.         for ( i=0; NEXT_header[i] != NULL; i++)
  283.             DPSPrintf(d,"%s",NEXT_header[i]);
  284.         DPSPrintf(d,"end\n");
  285. //        DPSPrintf(d,"%%%%EndProlog\n");
  286.         init_called=TRUE;
  287.         NEXT_init_pointsize = pointsize;
  288. }
  289.  
  290. static void window_create(float width, float height)
  291. {
  292.     initframe_called=TRUE;
  293.     
  294.     NXApp=[EpsViewer new];
  295.     [NXApp windowCreate:width Height:height];
  296. }
  297.  
  298. TERM_PUBLIC void NEXT_graphics()
  299. {
  300. struct termentry *t = term;
  301.     next_page++;
  302.     if(!init_called)
  303.         NEXT_init();    /* set up the frame properly */
  304.     init_called=FALSE;
  305. //    DPSPrintf(d,"%%%%Page: %d %d\n",next_page,next_page);
  306.     DPSPrintf(d,"gnudict begin\n");
  307.     DPSPrintf(d,"gsave\n");
  308.     DPSPrintf(d,"%d %d translate\n",NEXT_XOFF,NEXT_YOFF);
  309.     if (!next_portrait) {
  310. /* keep plot entirely in the window */
  311.         if(xsize>xsize_orig)
  312.             xsize=xsize_orig;
  313.         if(ysize>ysize_orig)
  314.             ysize=ysize_orig;
  315.         DPSPrintf(d,"%.3f %.3f scale\n", xsize/NEXT_SC, ysize/NEXT_SC);
  316.     }
  317.     else {
  318.         if(xsize>xsize_orig)
  319.             xsize=xsize_orig;
  320.         if(ysize>ysize_orig)
  321.             ysize=ysize_orig;
  322.         DPSPrintf(d,"%.3f %.3f scale\n", ysize/NEXT_SC, xsize/NEXT_SC);
  323.         DPSPrintf(d,"90 rotate\n0 %d translate\n", -NEXT_YMAX);
  324.     }
  325.     /* if (pointsize != PS_init_pointsize)
  326.         DPSPrintf(d, "/vpt %.1f def /hpt %.1f def /vpt2 vpt 2 mul def /hpt2 hpt 2 mul def\n",
  327.            pointsize*PS_VTIC*0.5, pointsize*PS_HTIC*0.5);
  328.     */
  329.     DPSPrintf(d,"0 setgray\n");
  330.     DPSPrintf(d,"/%s findfont %d ", next_font, (t->v_char) );
  331.     DPSPrintf(d,"scalefont setfont\n");
  332.     DPSPrintf(d,"newpath\n");
  333.     next_path_count = 0;    
  334. }
  335.  
  336.  
  337. TERM_PUBLIC void NEXT_text()
  338. {
  339.     next_path_count = 0;
  340.     DPSPrintf(d,"stroke\ngrestore\nend\nshowpage\n");
  341. //    DPSPrintf(d,"\ngrestoreall _the_saved_vm_ restore\n");
  342.         
  343.     DPSFlushContext(d);
  344.     
  345.     
  346. }
  347.  
  348.  
  349. TERM_PUBLIC void NEXT_reset()
  350. {    
  351.     DPSPrintf(d,"currentwindow termwindow\n");
  352.     DPSPrintf(d,"nulldevice\n");
  353.  
  354.     DPSFlushContext(d);
  355.     initframe_called=FALSE;
  356. }
  357.  
  358.  
  359. TERM_PUBLIC void NEXT_linetype(linetype)
  360. int linetype;
  361. {
  362. char *line = "ba012345678"; 
  363.     DPSPrintf(d,"LT%c\n", line[(linetype%9)+2]);
  364.     next_path_count = 0;
  365. }
  366.  
  367.  
  368. TERM_PUBLIC void NEXT_move(x,y)
  369. unsigned int x,y;
  370. {
  371.     DPSPrintf(d,"%d %d M\n", x, y);
  372.     next_path_count += 1;
  373. }
  374.  
  375.  
  376. TERM_PUBLIC void NEXT_vector(x,y)
  377. unsigned int x,y;
  378. {
  379.     DPSPrintf(d,"%d %d L\n", x, y);
  380.     next_path_count += 1;
  381.     if (next_path_count >= 400) {
  382.         DPSPrintf(d,"currentpoint stroke moveto\n");
  383.         next_path_count = 0;
  384.     }
  385. }
  386.  
  387.  
  388. TERM_PUBLIC void NEXT_put_text(x,y,str)
  389. unsigned int x, y;
  390. char *str;
  391. {
  392. char ch;
  393.     NEXT_move(x,y);
  394.     if (next_ang != 0)
  395.         DPSPrintf(d,"currentpoint gsave translate %d rotate 0 0 moveto\n"
  396.             ,next_ang*90);
  397. /*    NXPutc(psStream,'(');            */
  398.     DPSPrintf(d,"%c",'(');
  399.     ch = *str++;
  400.     while(ch!='\0') {
  401.         if ( (ch=='(') || (ch==')') || (ch=='\\') )
  402. /*            NXPutc(psStream,'\\');
  403.         NXPutc(psStream,ch);            */
  404.             DPSPrintf(d,"%c",'\\');
  405.         DPSPrintf(d,"%c",ch);
  406.         ch = *str++;
  407.     }
  408.     switch(next_justify) {
  409.         case LEFT : DPSPrintf(d,") Lshow\n");
  410.             break;
  411.         case CENTRE : DPSPrintf(d,") Cshow\n");
  412.             break;
  413.         case RIGHT : DPSPrintf(d,") Rshow\n");
  414.             break;
  415.     }
  416.     if (next_ang != 0)
  417.         DPSPrintf(d,"grestore\n");
  418.     next_path_count = 0;
  419. }
  420.  
  421. static int NEXT_text_angle(ang)
  422. int ang;
  423. {
  424.     next_ang=ang;
  425.     return TRUE;
  426. }
  427.  
  428. static int NEXT_justify_text(mode)
  429. enum JUSTIFY mode;
  430. {
  431.     next_justify=mode;
  432.     return TRUE;
  433. }
  434.  
  435. /* postscript point routines */
  436. TERM_PUBLIC void NEXT_point(x,y,number)
  437. unsigned int x,y;
  438. int number;
  439. {
  440. char *point = "PDABCTS";
  441.     number %= POINT_TYPES;
  442.      if (number < -1)
  443.         number = -1;        /* negative types are all 'dot' */
  444.     DPSPrintf(d,"%d %d %c\n", x, y, point[number+1]);
  445.     next_path_count = 0;
  446. }
  447. #endif /* TERM_BODY */
  448.  
  449. #ifdef TERM_TABLE
  450. TERM_TABLE_START(next_driver)
  451.     "next", "NeXTstep window system",
  452.        NEXT_XMAX, NEXT_YMAX, NEXT_VCHAR, NEXT_HCHAR,
  453.        NEXT_VTIC, NEXT_HTIC, NEXT_options, NEXT_init, NEXT_reset,
  454.        NEXT_text, null_scale, NEXT_graphics, NEXT_move, NEXT_vector,
  455.        NEXT_linetype, NEXT_put_text, NEXT_text_angle,
  456.        NEXT_justify_text, NEXT_point, do_arrow
  457. TERM_TABLE_END(next_driver)
  458.  
  459. #undef LAST_TERM
  460. #define LAST_TERM next_driver
  461.  
  462. #endif /* TERM_TABLE */
  463. #endif /* TERM_PROTO_ONLY  */
  464.  
  465. /*
  466.  * NAME: next
  467.  *
  468.  * OPTIONS: portrait|landscape (default landscape)
  469.  *        colour|monochrome (default monochrome)
  470.  *        font (default Helvetica)
  471.  *        fontsize (default 14)
  472.  *
  473.  * SUPPORTS: NeXTstep window system
  474.  *
  475.  * Further Info: 
  476.  * The PostScript driver with NXImage displaying the PostScript on screen 
  477.  *
  478.  * The `next' driver produces landscape output 10" wide and 7" high.  
  479.  * To change font to Times-Roman and font size to 20pts use 
  480.  * 'set term next "Times-Roman" 20'.
  481.  *
  482.  *
  483.  */